import org.apache.commons.lang3.StringUtils;

/**
 * @author faraday
 * @create 2020-08-27 17:14
 */
public class StringPlus {

    public static void main(String[] args) {
        String str = "hollis";
        long t1 = System.currentTimeMillis();
        for (int i = 0; i < 50000; i++) {
            String s = String.valueOf(i);
            str += s;
        }
        long t2 = System.currentTimeMillis();
        System.out.println("+ cost:" + (t2 - t1));
        System.out.println(str.length());
        str = "hollis";
        StringBuffer stringBuffer = new StringBuffer(str);
        for (int i = 0; i < 50000; i++) {
            stringBuffer.append(String.valueOf(i));
        }
        long t3 = System.currentTimeMillis();
        System.out.println("StringBuffer cost:" + (t3 - t2));
        System.out.println(stringBuffer.length());
        str = "hollis";
        StringBuilder stringBuilder = new StringBuilder(str);
        for (int i = 0; i < 50000; i++) {
            stringBuilder.append(String.valueOf(i));
        }
        long t4 = System.currentTimeMillis();
        System.out.println("stringBuilder cost:" + (t4 - t3));
        System.out.println(stringBuilder.length());
        str = "hollis";
        for (int i = 0; i < 50000; i++) {
            str = StringUtils.join(str, i);
        }
        long t5 = System.currentTimeMillis();
        System.out.println("StringUtils cost:" + (t5 - t4));
        System.out.println(str.length());
        str = "hollis";
        for (int i = 0; i < 50000; i++) {
            String s = String.valueOf(i);
            str += s;
        }
        long t6 = System.currentTimeMillis();
        System.out.println("+ cost:" + (t6 - t5));
        System.out.println(str.length());
    }
}
